package com.hontech.bvapp2.app

import android.Manifest
import com.hontech.bvapp2.store.Config
import com.hontech.bvapp2.ui.dialog.runProgErr
import com.hontech.bvapp2.utils.grantPermission
import com.hontech.bvapp2.utils.runOnUi


private var initFlag = false

private val initCbs = arrayListOf<suspend () -> Unit>()

fun globalInit() {
    if (initFlag) {
        return
    }
    initFlag = true

    runOnUi { initImpl() }
}

private suspend fun initImpl() {
    runProgErr("初始化") {
        grantPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
        grantPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
        Config.init()
    }
}


suspend fun runWithInit(cb: suspend () -> Unit) {
    if (initFlag) {
        cb()
    } else {
        initCbs.add(cb)
    }
}



























